package com.ruoyi.project.loan.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.loan.domain.ApprovalReport;
import com.ruoyi.project.loan.service.IApprovalReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 审批报告Controller
 *
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/loan/report" )
public class ApprovalReportController extends BaseController {
    @Autowired
    private IApprovalReportService approvalReportService;

    /**
     * 查询审批报告列表(不分页)
     */
    @PreAuthorize("@ss.hasPermi('loan:report:list')" )
    @GetMapping("/all/list" )
    public AjaxResult allList(ApprovalReport approvalReport) {
        List<ApprovalReport> list = approvalReportService.selectApprovalReportList(approvalReport);
        return success(list);
    }

    /**
     * 查询审批报告列表
     */
    @PreAuthorize("@ss.hasPermi('loan:report:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(ApprovalReport approvalReport) {
        startPage();
        List<ApprovalReport> list = approvalReportService.selectApprovalReportList(approvalReport);
        return getDataTable(list);
    }

    /**
     * 导出审批报告列表
     */
    @PreAuthorize("@ss.hasPermi('loan:report:export')" )
    @Log(title = "审批报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ApprovalReport approvalReport) {
        List<ApprovalReport> list = approvalReportService.selectApprovalReportList(approvalReport);
        ExcelUtil<ApprovalReport> util = new ExcelUtil<ApprovalReport>(ApprovalReport.class);
        util.exportExcel(response, list, "审批报告数据" );
    }

    /**
     * 获取审批报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('loan:report:query')" )
    @GetMapping(value = "/{reportId}" )
    public AjaxResult getInfo(@PathVariable("reportId" ) Long reportId) {
        return success(approvalReportService.selectApprovalReportByReportId(reportId));
    }

    /**
     * 新增审批报告
     */
    @PreAuthorize("@ss.hasPermi('loan:report:add')" )
    @Log(title = "审批报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApprovalReport approvalReport) {
        return toAjax(approvalReportService.insertApprovalReport(approvalReport));
    }

    /**
     * 修改审批报告
     */
    @PreAuthorize("@ss.hasPermi('loan:report:edit')" )
    @Log(title = "审批报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApprovalReport approvalReport) {
        return toAjax(approvalReportService.updateApprovalReport(approvalReport));
    }

    /**
     * 删除审批报告
     */
    @PreAuthorize("@ss.hasPermi('loan:report:remove')" )
    @Log(title = "审批报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportIds}" )
    public AjaxResult remove(@PathVariable Long[] reportIds) {
        return toAjax(approvalReportService.deleteApprovalReportByReportIds(reportIds));
    }
}
